package com.ellecity06.common.widgets.touch

import android.R.attr.height
import android.view.MotionEvent
import android.view.View
import com.ellecity06.common.ktx.dp2px
import com.ellecity06.common.ktx.height
import com.ellecity06.common.utils.logD

/**
 * @author ellecity06
 * @time 2025/3/28 17:44
 * @des
 */
class DragHeightHelper(private val view: View) {
    private var lastY = 0
    private var tempHeight = 160f.dp2px()
    private val dp160  = 100f.dp2px()
    fun onTouchEvent(event: MotionEvent): Boolean {
        when (event.action) {
            MotionEvent.ACTION_DOWN -> {
                lastY = event.rawY.toInt()
            }

            MotionEvent.ACTION_MOVE -> {
                val dy = (event.rawY - lastY).toInt()
//					LiveEventBus.get<Int>("videoMargin").post(dy)
                logD("tempHeight=${tempHeight},, dy=${dy} ,,oo=${100..450f.dp2px()}")
                if (tempHeight - dy in dp160..450f.dp2px())
                    view.height(tempHeight - dy)
            }

            MotionEvent.ACTION_UP -> {
                lastY = event.rawY.toInt()
                tempHeight = view.height
//					mBinding.videoView.invalidate()
            }
        }
       return true
    }
}